package com.sso.cas;

import org.jasig.services.persondir.IPersonAttributes;
import org.jasig.services.persondir.support.AttributeNamedPersonImpl;
import org.jasig.services.persondir.support.StubPersonAttributeDao;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;

@Component(value="attributeRepository")
public class UserStubPersonAttributeDao extends StubPersonAttributeDao {
    @Resource
    private UserDaoJdbc userDaoJdbc;  
      
    @Override  
    public IPersonAttributes getPerson(String uid) {
        Map<String, List<Object>> attributes = new HashMap<String, List<Object>>();
        try {  
            User user = userDaoJdbc.getByUsername(uid);  
            attributes.put("userId", Arrays.<Object>asList(user.getId()));
            attributes.put("username", Collections.singletonList((Object)user.getUsername()));  
            attributes.put("usernamePlain", Collections.singletonList((Object) URLEncoder.encode(user.getPassword(), "UTF-8")));
            attributes.put("blogURL", Collections.singletonList((Object)"http://liutieyer"));
            attributes.put("blogger", Collections.singletonList((Object)URLEncoder.encode("刘毅", "UTF-8")));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();  
        }  
        return new AttributeNamedPersonImpl(attributes);
    }  
}  